package org.restorator.utill;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Utill class for some general operations.
 */
public class GeneralUtil {

    private GeneralUtil() { }

    public static String getClassName() {
        try {
            throw new RuntimeException();
        } catch (RuntimeException e) {
            return e.getStackTrace()[1].getClassName();
        }
    }

    public static void closeInSilence(Connection c) {
        if(c != null) {
            try {
                c.close();
            } catch (SQLException ignored) { }
        }
    }

    public static void closeInSilence(Statement s) {
        if(s != null)
            try {
                s.close();
            } catch (SQLException ignored) { }
    }

    public static void closeInSilence(ResultSet rs) {
        if(rs != null) {
            try {
                rs.close();
            } catch (SQLException ignored) { }
        }
    }

    public static boolean isDigit(String str) {
        if(str != null && !str.isEmpty()) {
            for (int i = 0; i < str.length(); i++) {
                if(!Character.isDigit(str.charAt(i))) return false;
            }
            return true;
        } else {
            return false;
        }
    }

}
